﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Model.WXshopBuiness;
using Xproject.Framework.Core.Repositories;
using Xproject.Framework.Utility.Extensions;


namespace Repository.WXshopBuiness
{
   public static class PromotionKJDetailRep
    {
        public static PromotionsKanJiaDetail GetByIdAndUserId(this IRepositoryAsync<PromotionsKanJiaDetail> repository, string kanJiaID,string UserId)
        {
            Expression<Func<PromotionsKanJiaDetail, bool>> expression = i => 1 == 1;
            if (string.IsNullOrEmpty(kanJiaID))
            {
                return null;
            }
            else
            {
                expression = expression.AndAlso(i => i.KanJiaID == kanJiaID);
            }
            if (string.IsNullOrEmpty(UserId))
            {
                return null;
            }
            else
            {
                expression = expression.AndAlso(i => i.UserID == UserId);
            }

            return repository.Query().Where(expression).Select().FirstOrDefault();
        }

        public static List<PromotionsKanJiaDetail> GetKJDetailList(this IRepositoryAsync<PromotionsKanJiaDetail> repository, string kanJiaID)
        {
            Expression<Func<PromotionsKanJiaDetail, bool>> expression = i => 1 == 1;
            if (string.IsNullOrEmpty(kanJiaID))
            {
                return null;
            }
            else
            {
                expression = expression.AndAlso(i => i.KanJiaID == kanJiaID);
            }
            return repository.Query().Where(expression).Select().OrderByDescending(i=>i.KanJiaMoney).ToList();
        }
    }
}
